/*
*   复数计算器
* 
*   夏思成
* 
*   2024年3月21日
* 
*   实验室二机房
*/
#include <iostream>
using namespace std;

class plural
{

public:
    //构造函数 
    plural(float x = 0, float y = 0)
    {
        real = x;
        imag = y;
    }
    //析构函数
    ~plural()
    {
        //cout<<"plural deleted"<<endl;
    }

    //加法函数 
    plural Add(plural p1, plural p2)
    {
        plural c;
        c.real = p1.real + p2.real;
        c.imag = p1.imag + p2.imag;
        return  c;
    }

    //减法函数
    plural Min(plural p1, plural p2)
    {
        plural c;
        c.real = p1.real - p2.real;
        c.imag = p1.imag - p2.imag;
        return  c;
    }

    //乘法函数
    plural Mul(plural p1, plural p2)
    {
        plural c;
        c.real = p1.real * p2.real;
        c.imag = p1.imag * p2.imag;
        return  c;
    }

    //除法函数
    plural Div(plural p1, plural p2)
    {
        plural c;
        c.real = p1.real / p2.real;
        c.imag = p1.imag / p2.imag;
        return  c;
    }
    void calc(plural(*pf)(plural, plural))
    {
        //创建plural型变量 
        plural a(1.0, 2.0);
        plural b(2.0, 4.0);
        plural c;
        pf(a, b);
        cout << "计算结果为:" << endl;
        cout << c.real << "," << c.imag << endl;
    }
private:
    float real;//复数实部 
    float imag;//复数虚部 
};

//菜单函数
void Print_menu()
{
    cout << "******1.Add******" << endl;
    cout << "******2.Min******" << endl;
    cout << "******3.Mul*******" << endl;
    cout << "******4.Div*******" << endl;
    cout << "******0.exit******" << endl;
}

void test()
{
    plural c;
    plural d;
    int n = 0;
    do
    {
        //菜单打印 
        Print_menu();

        //模式选择 
        cin >> n;

        switch (n)
        {
        case 1:
            (c.calc(c.Add);
            break;
        case 2:
            //calc(Min);
            break;
        case 3:
            //calc(Mul);
            break;
        case 4:
            //clac(Div);
            break;
        case 0:
            cout << "退出复数计算器" << endl;
            break;
        default:
            cout << "非法输入，请重新选择" << endl;
            break;
        }
    } while (n);
}

int main()
{
    test();
    return 0;
}